package shared.pojo.mission

import shared.Pojo._
import shared.implicits.Implicits._
import shared.tool.DefaultPickle
import upickle.default._

/** Created by yz on 15/5/2023
  */
object HeatmapPlot extends HeatmapT {

  def pngFileNamePrefixIn = {
    s"heatmap"
  }

  def pngFileNamePrefix(idStr: String) = {
    if (idStr.nonBlank) {
      s"${idStr}/${pngFileNamePrefixIn}"
    } else {
      s"${pngFileNamePrefixIn}"
    }
  }

  def configFileName = {
    s"${name}.json"
  }

  case class LayoutData(
      rowCluster: String = "F",
      rowClusterMethod: String = "complete",
      colCluster: String = "F",
      colClusterMethod: String = "complete",
      width: String = "7",
      height: String = "7",
      rowTreeHeight: String = "50",
      colTreeHeight: String = "50",
      rowNum: Int = 10,
      colNum: Int = 10,
      splitNum: String = "1",
      colSplitNum: String = "1",
      convMethod: String = "zScale",
      normal: String = "row",
      log: String = "lg2",
      hasBorder: String = "white",
      showPart: String = "full",
  )

  object LayoutData {
    implicit val rw = macroRW[LayoutData]
    implicit val defaultRw = DefaultPickle.macroRW[LayoutData]
  }

  val customColors = List("#1E90FF", "#FFFFFF", "#E41A1C")

  case class ColorData(
      colorsStr: String = customColors.mkString(":"),
      customColors: List[String] = customColors,
      naColor: String = "#DDDDDD",
      gradientNum: String = "30",
      borderColor: String = "#ffffff",
      rowGroups:List[String]=List.empty,
      annoRowColors:String="",
      colGroups:List[String]=List.empty,
      annoColColors:String="",
  )

  object ColorData {
    implicit val rw = macroRW[ColorData]
    implicit val defaultRw = DefaultPickle.macroRW[ColorData]
  }

  case class FontData(
      fontFamily: String = "Times",
      showColName: String = "T",
      showNumber: String = "F",
      xFont: String = "10",
      cellFont: String = "6",
      xRotate: String = "315",
      showRowName: String = "T",
      yRotate: String = "0",
      yFont: String = "9",
      legendFont: String = "9",
      legendTitle: String = "Z-Score",
      legendTitleFont: String = "12",
      mainTitle:String=""
  )

  object FontData {
    implicit val rw = macroRW[FontData]
    implicit val defaultRw = DefaultPickle.macroRW[FontData]
  }

  case class Request(
      id: Int = 0,
      idStr: String = "",
      kind: String = s"${name}",
      layout: LayoutData = LayoutData(),
      color: ColorData = ColorData(),
      font: FontData = FontData()
  )

  object Request {
    implicit val rw = macroRW[Request]
    implicit val defaultRw = DefaultPickle.macroRW[Request]
  }

}
